<?php
class Controller extends Core {
	
	
	public function __construct($registry) {
		parent::__construct($registry);
	}
	
	protected function render($return = FALSE) {
		foreach ($this->children as $child) {
			$action = new Action($child);
			$file   = $action->getFile();
			$class  = $action->getClass();
			$method = $action->getMethod();
			$args   = $action->getArgs();
		
			if (file_exists($file)) {
				require_once($file);

				$controller = new $class($this->registry);
				
				$controller->index();
				
				$this->data[$controller->id] = $controller->output;
			} else {
				exit('Error: Could not load controller ' . $child . '!');
			}
		}
		
		if ($return) {
			
			$this->data['pachara'] = $this->fetch($this->template);
			
			if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/core.tpl')) {
				$this->template = $this->config->get('config_template') . '/template/common/core.tpl';
			} else {
				$this->template = 'default/template/common/home.tpl';
			}			
			
			
			
			return $this->fetch($this->template);
		} else {
			$this->output = $this->fetch($this->template);
		}
	}
	
	
}
?>